package com.fqy.servlet;

import com.fqy.dao.PeopleDaoImpl;
import com.fqy.dao.impl.PeopleDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import static com.fqy.servlet.UpdateServlet.toInt;

public class DeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PeopleDao PeopleDao = new PeopleDaoImpl();
        int id = toInt(req.getParameter("id"));
        int i = PeopleDao.deletePeople(id);
        resp.setCharacterEncoding("GBK");//编码方式
        PrintWriter out = resp.getWriter();
        if (i > 0) {
            out.println("删除成功");
        } else {
            out.println("删除失败");
        }
    }
}
